<template>
  <div class="gl_heightFull gl_contentBox">
    <div style="margin-bottom:15px">
      <el-button type="success" size="mini" @click="openOrgan">新增联合考试机构</el-button>
    </div>
    <div class="demo-input-suffix gl_searchBox">
      <el-row :gutter="20">
        <el-col :md="4" :lg="4">
          <p>受邀状态</p>
          <el-select v-model="IsEnabled" size="mini" @change="gettablelist()">
            <el-option label="全部" value="" />
            <el-option label="待同意" value="Pending" />
            <el-option label="已接受" value="Accept" />
          </el-select>
        </el-col>
        <el-col :md="4" :lg="4">
          <p>机构名称</p>
          <el-input v-model="Api_GET_ClubDuanExamParticipatingUnitQO.Filter" placeholder="请输入机构名称" size="mini" clearable @change="gettablelist()" />
        </el-col>
        <el-col :md="4" :lg="4">
          <p>机构地址</p>
          <el-input v-model="Api_GET_ClubDuanExamParticipatingUnitQO.Address" placeholder="请输入地址名称" size="mini" clearable @change="gettablelist()" />
        </el-col>
        <el-col :md="4" :lg="4">
          <p>联系人</p>
          <el-input v-model="Api_GET_ClubDuanExamParticipatingUnitQO.Contact" placeholder="请输入联系人名称" size="mini" clearable @change="gettablelist()" />
        </el-col>
        <el-col :md="4" :lg="4">
          <p>联系电话</p>
          <el-input v-model="Api_GET_ClubDuanExamParticipatingUnitQO.PhoneNumber" placeholder="请输入电话号码" size="mini" clearable @change="gettablelist()" />
        </el-col>
        <el-col :md="4" :lg="4">
          <el-button type="primary" style="margin-top:25px" size="mini" @click="gettablelist()">筛选</el-button>
          <el-button type="warning" size="mini" @click="reset()">{{ $t('button.Reset') }}</el-button>
        </el-col>
      </el-row>
    </div>

    <div style="margin-top:15px">
      <el-table v-loading="tableLoading" class="gl_table_noBorder" size="mini" :data="tableData">
        <el-table-column label="序号" type="index" align="center" width="55" />
        <el-table-column label="机构名称" prop="participatingUnitName" />
        <el-table-column label="机构地址" prop="address" />
        <el-table-column label="联系人" prop="contact" />
        <el-table-column label="联系人电话" prop="phoneNumber" />
        <el-table-column label="受邀状态" align="center">
          <template slot-scope="{row}">
            <span v-for="item in dict.duanExamParticipatingUnitStatus" :key="item.code">{{ item.code == row.statusCode ? item.value : '' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="160">
          <template slot-scope="{ row }">
            <el-button size="mini" type="text" @click="close(row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <Addorgain ref="Addorgain" />
    <el-row class="gl_pt_15" style="text-align: right;">
      <el-pagination
        :current-page="Api_GET_ClubDuanExamParticipatingUnitQO.Page"
        :page-size="Api_GET_ClubDuanExamParticipatingUnitQO.MaxResultCount"
        :total="totalPage"
        layout="total,sizes,prev,pager,next,jumper"
        :page-sizes="[10, 20, 30, 40]"
        @size-change="sizeChange"
        @current-change="pageIndexChange"
      />
    </el-row>
  </div>
</template>

<script>
import { mapState, mapActions } from 'vuex';
import { api_GET_ClubDuanExamParticipatingUnit, api_POST_ClubDuanExamParticipatingUnitIdDisable } from '@/extend/api/hallswaggerApi/app.js';
import { Api_GET_ClubDuanExamParticipatingUnitQO } from '@/lib/form/hall/swaggerForm';

import Addorgain from './component/addOrganization.vue';
export default {
  components: {
    Addorgain
  },
  data() {
    return {
      tableData: [],
      tableLoading: false,
      IsEnabled: '',
      totalPage: 0,
      Api_GET_ClubDuanExamParticipatingUnitQO: new Api_GET_ClubDuanExamParticipatingUnitQO() // 可参报机构
    };
  },
  computed: {
    ...mapState({
      dict: state => state.dict.dict,
      user: state => state.user.currentOU
    })
  },
  created() {
    this.gettablelist();
    this.getDict();
  },

  methods: {
    ...mapActions({ getDict: 'dict/getDict', getDictByType: 'dict/getDictByType' }),
    // 获取可参保机构列表
    gettablelist(page) {
      this.tableLoading = true;
      this.Api_GET_ClubDuanExamParticipatingUnitQO.DuanExamId = this.$route.query.id; // type: string
      this.Api_GET_ClubDuanExamParticipatingUnitQO.Sorting = 'creationTime DESC';
      this.Api_GET_ClubDuanExamParticipatingUnitQO.Page = page || 1;
      this.Api_GET_ClubDuanExamParticipatingUnitQO.SkipCount = (this.Api_GET_ClubDuanExamParticipatingUnitQO.Page - 1) * this.Api_GET_ClubDuanExamParticipatingUnitQO.MaxResultCount;
      this.Api_GET_ClubDuanExamParticipatingUnitQO.StatusCode = this.IsEnabled;
      this.Api_GET_ClubDuanExamParticipatingUnitQO.IsEnabled = true;
      this.Api_GET_ClubDuanExamParticipatingUnitQO.IncludeStatus = true;
      console.log(this.Api_GET_ClubDuanExamParticipatingUnitQO);
      api_GET_ClubDuanExamParticipatingUnit(this.Api_GET_ClubDuanExamParticipatingUnitQO).then(res => {
        this.totalPage = res.totalCount;
        this.tableData = res.items;
        this.tableLoading = false;
      }, error => {
        this.tableLoading = false;
        const _msg = error.error.message || error.message;
        this.$message({ type: 'error', message: _msg });
      });
    },
    // 打开新增
    openOrgan() {
      this.$refs.Addorgain.dialogEditVisible = true;
      this.$refs.Addorgain.gettablelist();
    },
    // 分页按钮
    sizeChange(MaxResultCount) {
      this.Api_GET_ClubDuanExamParticipatingUnitQO.MaxResultCount = MaxResultCount;
      this.gettablelist();
    },
    pageIndexChange(currentPage) {
      this.gettablelist(currentPage);
    },
    // 重置按钮
    reset () {
      this.Api_GET_ClubDuanExamParticipatingUnitQO = new Api_GET_ClubDuanExamParticipatingUnitQO();
      this.IsEnabled = '';
      this.gettablelist();
    },
    // 删除按钮
    close(id) {
      this.$confirm(`您确定要删除吗？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          api_POST_ClubDuanExamParticipatingUnitIdDisable(id).then(res => {
            this.$message({
              message: '删除成功',
              type: 'success'
            });
            this.gettablelist();
          }, error => {
            const _msg = error.error.message || error.message;
            this.$message({ type: 'error', message: _msg });
          });
        });
    }
  }

};
</script>

<style>

</style>
